#!/bin/bash

# Slackware build script for neutral

# Written by Grigorios Bouzakis (grbzks@xsmail.com)
# Ryan P.C. McQuen | Everett, WA | ryanpcmcquen@member.fsf.org
# Copyright 2022, Alexander Verbovetsky, Moscow, Russia
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=neutral
VERSION=${VERSION:-1.13a}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

ARCH=noarch

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM
tar xvf $CWD/28310-$PRGNAM-$VERSION.tar.gz
cd $PRGNAM
chown -R root:root .
find -L . \
 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  -o -perm 511 \) -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

ln -sf X_cursor cursors/pirate
ln -sf based_arrow_down cursors/base_arrow_down
ln -sf based_arrow_up cursors/base_arrow_up
ln -sf bd_double_arrow cursors/c7088f0f3e6c8088236ef8e1e3e70000
ln -sf center_ptr cursors/centre_ptr
ln -sf copy cursors/1081e37283d90000800003c07f3ef6bf
ln -sf copy cursors/6407b0e94181790501fd1e167b474872
ln -sf cross cursors/cross_reverse
ln -sf cross cursors/diamond_cross
ln -sf crossed_circle cursors/03b6e0fcb3499374a867c041f52298f0
ln -sf dotbox cursors/dot_box_mask
ln -sf dotbox cursors/draped_box
ln -sf dotbox cursors/icon
ln -sf dotbox cursors/target
ln -sf fd_double_arrow cursors/fcf1c3c7cd4491d801f1e1c78f100000
ln -sf hand1 cursors/9d800788f1b08800ae810202380a0822
ln -sf hand1 cursors/e29285e634086352946a0e7090d73106
ln -sf hand1 cursors/hand
ln -sf hand1 cursors/hand2
ln -sf left_ptr cursors/arrow
ln -sf left_ptr cursors/top_left_arrow
ln -sf left_ptr_watch cursors/08e8e1c95fe2fc01f976f1e063a24ccd
ln -sf left_ptr_watch cursors/3ecb610c1bf2410f44200f48c40d3599
ln -sf link cursors/3085a0e285430894940527032f8b26df
ln -sf link cursors/640fb0e74195791501fd1ed57b41487f
ln -sf move cursors/4498f0e0c1937ffe01fd06f973665830
ln -sf move cursors/9081237383d90e509aa00f00170e968f
ln -sf question_arrow cursors/5c6cd98b3f3ebcb1f9c7f1c204630408
ln -sf question_arrow cursors/d9ce0ab605698f320427677b458ad60b
ln -sf question_arrow cursors/help
ln -sf question_arrow cursors/left_ptr_help
ln -sf right_ptr cursors/draft_large
ln -sf right_ptr cursors/draft_small
ln -sf sb_h_double_arrow cursors/028006030e0e7ebffc7f7070c0600140
ln -sf sb_h_double_arrow cursors/14fef782d02440884392942c11205230
ln -sf sb_h_double_arrow cursors/h_double_arrow
ln -sf sb_v_double_arrow cursors/00008160000006810000408080010102
ln -sf sb_v_double_arrow cursors/2870a09082c103050810ffdffffe0204
ln -sf sb_v_double_arrow cursors/double_arrow
ln -sf sb_v_double_arrow cursors/v_double_arrow

rmdir source/cursors

mkdir -p $PKG/usr/share/icons/neutral
cp -a cursors $PKG/usr/share/icons/neutral/

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a source $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
